import Vuex from 'vuex';
import Vue from 'vue'

// 导入子模块 user.js
import user from './moudles/user'
// 导入子模块 shop.js
import shop from './moudles/shop'
Vue.use(Vuex);
const store = new Vuex.Store({
    state: {
        count: 0
    },
    mutations: { // 同步方法
        addcount(state, step) {
            state.count += step
        },
        jiancount(state) {
            state.count -= 1
        }
    },
    actions: { //异步方法
        addCountAsync({ commit }, step) {
            setTimeout(() => {
                commit('addcount', step)
            }, 2000)
        },
        jianCountAsync({ commit }) {
            setTimeout(() => {
                commit('jiancount')
            }, 2000)
        }

    },
    getters: { // 计算属性
        doubleCount(state) {
            return state.count * 2
        }

    },
    modules: { // 模块
        userModule: user,
        shopModule: shop
    }
})

export default store